#!/usr/local/bin/perl 
#
#Author: eb4
#
use strict;
use warnings;
use CGI;
use LWP::Simple qw($ua);
use URI::Escape;
use Cache::File;
##use Smart::Comments;

local $| = 1;
warn "Initialising cache";
our $cache ||= Cache::File->new( cache_root => '/tmp/cache' );

my $q = CGI->new;

my $url    = $q->param('s');
warn "Got url = $url";

$ua->timeout(5);

$ua->proxy( 'http', 'http://webcache.sanger.ac.uk:3128');

print "Content-type: text/xml\n\n";

my $content;

if ($content = $cache->get($url)) {
  warn "Got $url from cache";
  print $content;
} else {
  warn "LWP getting $url";
  $content = LWP::Simple::get($url);
  warn "Got it";
  print $content;
  $cache->set($url, $content);
}
